package com.ruoyi.yf.config;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.ruoyi.yf.tool.barcode.GenerateBarcode;

import java.awt.*;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 生成条码
 * bbf8943b-d827-4e8d-9b6e-98a9bc4379ef
 */

public class BarcodeConfig {

    private static final long serialVersionUID = 1L;

    public static void main(String asg[]) {

        BarcodeConfig generateBarcode = new BarcodeConfig();
        generateBarcode.setCodeno(1);
//        generateBarcode.setfileno(7);
        generateBarcode.setIstext(true);
        generateBarcode.setIsbrcode(true);
        generateBarcode.setIsqrcode(true);
        generateBarcode.setCompress(true);

//        String p = GenerateBarcode.generate(generateBarcode, "/Users/xingyipeng/Desktop/2020_1w/", "xing");
//        System.out.println(p);

    }


    //生成文件夹个数
    private int fileno;

    //生成条码总数
    private int codeno;


    //text 生成 判断
    private boolean istext;

    //条形码 生成 判断
    private boolean isbrcode;

    //二维码 生成 判断
    private boolean isqrcode;


    //每个文件夹石否压缩
    private boolean compress;

    //医院
    private String hospital;

    //备注
    private String remark;

    //验证密码成功生成
    private String password;

    //是否验证
    private boolean validation;

    //创建者姓名
    private String creatbyname;


    //二维码宽度、高度
    private int wight;
    private int height;

    // 设置边距，既二维码和背景之间的边距
    private int margin;

    // 设置前景色，既二维码颜色（青色）
    private int[] foreColor;
    // 设置背景色（灰色）
    private int[] backColor;

    //二维码背景
    private Image logo;

    // 二维码 高纠错级别
    private String errorCorrection;


    //二维码 配置
    public QrConfig getQrConfig() {
        QrConfig config = new QrConfig();
        if (wight < 1)
            this.wight = 300;
        if (height < 1)
            this.height = 300;

        if (margin < -1)
            this.margin = 1;

        config.setWidth(wight);
        config.setHeight(height);
        config.setMargin(margin);

        if (foreColor != null && foreColor.length == 3)
            config.setForeColor(new Color(foreColor[0], foreColor[1], foreColor[2]));
        else
            config.setForeColor(Color.BLACK);

        if (backColor != null && backColor.length == 3)
            config.setBackColor(new Color(backColor[0], backColor[1], backColor[2]));
        else
            config.setBackColor(Color.white);

        if (logo != null)
            config.create().setImg(logo);


        if (errorCorrection == null) {
            config.setErrorCorrection(ErrorCorrectionLevel.H);//约30％校正
        } else if (errorCorrection.equals("L"))
            config.setErrorCorrection(ErrorCorrectionLevel.L);//约7％的校正
        else if (errorCorrection.equals("M"))
            config.setErrorCorrection(ErrorCorrectionLevel.M);//15％校正
        else if (errorCorrection.equals("Q"))
            config.setErrorCorrection(ErrorCorrectionLevel.Q);//25％校正
        else if (errorCorrection.equals("H"))
            config.setErrorCorrection(ErrorCorrectionLevel.H);//约30％校正
        else
            config.setErrorCorrection(ErrorCorrectionLevel.H);//约30％校正

        return config;
    }


    public int getfileno() {
        return fileno;
    }

    public void setfileno(int fileno) {
        this.fileno = fileno;
    }


    public boolean isIstext() {
        return istext;
    }

    public void setIstext(boolean istext) {
        this.istext = istext;
    }

    public boolean isIsbrcode() {
        return isbrcode;
    }

    public void setIsbrcode(boolean isbrcode) {
        this.isbrcode = isbrcode;
    }

    public boolean isIsqrcode() {
        return isqrcode;
    }

    public void setIsqrcode(boolean isqrcode) {
        this.isqrcode = isqrcode;
    }

    public String getCreatbyname() {
        return creatbyname;
    }

    public void setCreatbyname(String creatbyname) {
        this.creatbyname = creatbyname;
    }

    public boolean isCompress() {
        return compress;
    }

    public void setCompress(boolean compress) {
        this.compress = compress;
    }

    public String getHospital() {
        return hospital;
    }

    public void setHospital(String hospital) {
        this.hospital = hospital;
    }


    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }


    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isValidation() {
        return validation;
    }

    public void setValidation(boolean validation) {
        this.validation = validation;
    }



    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getcreatbyname() {
        return creatbyname;
    }

    public void setcreatbyname(String creatbyname) {
        this.creatbyname = creatbyname;
    }

    public int getWight() {
        return wight;
    }

    public void setWight(int wight) {
        this.wight = wight;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getMargin() {
        return margin;
    }

    public void setMargin(int margin) {
        this.margin = margin;
    }

    public int[] getForeColor() {
        return foreColor;
    }

    public void setForeColor(int[] foreColor) {
        this.foreColor = foreColor;
    }

    public int[] getBackColor() {
        return backColor;
    }

    public void setBackColor(int[] backColor) {
        this.backColor = backColor;
    }

    public Image getLogo() {
        return logo;
    }

    public void setLogo(Image logo) {
        this.logo = logo;
    }

    public String getErrorCorrection() {
        return errorCorrection;
    }

    public void setErrorCorrection(String errorCorrection) {
        this.errorCorrection = errorCorrection;
    }

    public int getFileno() {
        return fileno;
    }

    public void setFileno(int fileno) {
        this.fileno = fileno;
    }

    public int getCodeno() {
        return codeno;
    }

    public void setCodeno(int codeno) {
        this.codeno = codeno;
    }

    @Override
    public String toString() {
        return "BarcodeConfig{" +
                "fileno=" + fileno +
                ", codeno=" + codeno +
                ", istext=" + istext +
                ", isbrcode=" + isbrcode +
                ", isqrcode=" + isqrcode +
                ", compress=" + compress +
                ", hospital='" + hospital + '\'' +
                ", remark='" + remark + '\'' +
                ", password='" + password + '\'' +
                ", validation=" + validation +
                ", creatbyname='" + creatbyname + '\'' +
                ", wight=" + wight +
                ", height=" + height +
                ", margin=" + margin +
                ", foreColor=" + Arrays.toString(foreColor) +
                ", backColor=" + Arrays.toString(backColor) +
                ", logo=" + logo +
                ", errorCorrection='" + errorCorrection + '\'' +
                '}';
    }
}


